package Controller.message;

import Models.dao.TransactionalDao;
import Models.enity.Pagination;
import Models.enity.Transactional;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/message/history")
public class EventHandleHistory extends HttpServlet {
    private static String PublicPath = "/WEB-INF/views";
    private TransactionalDao transactionalDao = new TransactionalDao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int currentPage = 1;
        if(req.getParameter("page") != null) currentPage = Integer.parseInt(req.getParameter("page"));

        Pagination pagination = new Pagination(5,currentPage);
        int allData = (int)transactionalDao.findDataSize();
        pagination.setAllPages(allData);
        pagination.PageData = transactionalDao.findPaginationData(pagination.skip,pagination.getPageSize());
        req.setAttribute("pagination",pagination);
        req.getRequestDispatcher(PublicPath + "/message/history.jsp").forward(req,resp);
    }
}
